﻿
@{
    ViewBag.Title = "客户列表 ";
    Layout = "~/Views/Shared/Master.cshtml";
}
<div class="page-content">
    <!-- BEGIN PAGE HEADER-->
    <div class="page-bar">
        <ul class="page-breadcrumb">
            <li>
                <a href="~/Home/Main">首页</a>
                <i class="fa fa-angle-double-right"></i>
            </li>
            <li>
                <a href="#">客户列表</a>
                <i class="fa fa-angle-double-right"></i>
            </li>
        </ul>
    </div>
    <!-- BEGIN PAGE TITLE-->
    <h3 class="page-title">
        订单管理
    </h3>
    <!--biaoge-->
    <div class="portlet light">
        <div class="portlet-title">
            <div class="caption"><i class="fa fa-envelope font-yellow-casablanca"></i><span class="caption-subject bold font-yellow-casablanca">客户列表</span></div>
            @*<a class="btn green-meadow kuan" href="javascript:;"><i class="fa fa-plus"></i> 新 增</a>*@
        </div>
        <!-- END PAGE TITLE-->
        <div class="search_1">
            <form action="~/Home/GetOrder" method="post" id="grform" class="horizontal-form">
                <div class="form-body">
                    <div class="row se_le">
                        <!--/span-->
                        <div class="se_pad2">
                            <div class="form-group se_bot">
                                <label class="control-label se_le1">客户姓名</label>
                                <div class="se_pad1 padding_le5">
                                    <input type="text" id="CName" name="CName" class="form-control" placeholder="客户姓名">
                                </div>
                            </div>
                        </div>
                        <!--/span-->
                        <div class="se_pad2">
                            <div class="form-group se_bot">
                                <label class="control-label se_le1">客户手机号</label>
                                <div class="se_pad1 padding_le5">
                                    <input type="text" id="Phone" name="Phone" class="form-control" placeholder="客户手机号">
                                </div>
                            </div>
                        </div>

                        <div class="cx">
                            <div class="form-group se_bot"><a class="btn btn-primary" onclick="ChaXun();" href="javascript:;"><i class="fa fa-search"></i> 查询</a></div>
                        </div>
                    </div>
                </div>
            </form>
        </div>
        <div class="portlet-body">
            <div class="table-scrollable_1 table-scrollable-borderless">
                <table class="table table-striped table-hover table-checkable order-column dataTable no-footer table_ri bordered_bott">
                    <thead>
                        <tr>
                            <th>序号</th>
                            <th>客户姓名</th>
                            <th>手机号</th>
                            <th>年龄</th>
                            <th>性别</th>
                            <th>等级</th>
                            <th>地址</th>
                            <th>已关联订单数</th>
                            <th>操作</th>
                        </tr>
                    </thead>
                    <tbody id="tbody"></tbody>
                </table>
                <div style="margin-bottom:50px;" id="fenye">
                    <button class="layui-btn layui-btn-xs" style="float:left" onclick="LastPage();">上一页</button>
                    <div style="padding:inherit;float:left;width:78px;height:38px;"><div style="margin-top:8px;text-align:center;" id="pagecounttext"></div></div>
                    <button class="layui-btn layui-btn-xs" style="float:left" onclick="NextPage();">下一页</button>
                    <div style="height:38px;width:500px;float:left;">
                        <div><span style="float:left;margin-left:10px;margin-top:8px;">跳转至</span></div>
                        <div style="height:38px;">
                            <input type="text" id="pagecount" style="margin-left:20px;margin-top:7px; width:50px;" />
                            <button class="" style="margin-left:20px;margin-top:7px; width:50px;" onclick="JumpPage();">确定</button>
                        </div>
                    </div>
                </div>
            </div>

        </div>
    </div>
</div>


<script src="~/Scripts/jquery-1.10.2.min.js"></script>
<script src="~/Scripts/layui/layui.js"></script>
<script>

</script>
<script>
    var pageindex = 1;
    var pagecount;
    $(function () {
        pageindex = 1;
        GetPage();
    });
    function GetPage() {
        $.ajax({
            url: "/Home/GetCustomerPage",
            data: {
                pageindex: pageindex,
                Phone: $("#Phone").val(),
                CName: $("#CName").val()
            },
            success: function (result) {
                if (result.totalcount>0) {
                    var str = ToHtml(result.list);
                    $("#tbody").html('');
                    $("#tbody").html(str);
                    $("#pagecounttext").text(pageindex + "/" + result.pagecount);
                    pagecount = result.pagecount;
                    $("#fenye").show();
                } else {
                    $("#tbody").html('暂无数据');
                    $("#fenye").hide();
                }
            }
        });
    }
    function ChaXun() {
        pageindex = 1;
        GetPage();
    }
    function LastPage() {
        if (pageindex > 1) {
            pageindex--;
            GetPage();
        }
    }
    function NextPage() {
        if (pageindex < pagecount) {
            pageindex++;
            GetPage();
        }
    }
    function JumpPage() {
        var c = $("#pagecount").val();
        if (!isNaN(c) && c >= 1 && c <= pagecount) {
            pageindex = c;
            GetPage();
        }
    }

    function ToHtml(data) {
        var str = "";
        $.each(data, function (i, item) {
            str += "<tr><td>" + (i + 1) + "</td>";
            str += "<td>" + item.Name + "</td>";
            str += "<td>" + item.Phone + "</td>";
            str += "<td>" + item.Age + "</td>";
            str += "<td>" + item.Sex + "</td>";
            str += "<td>" + item.Stars + "</td>";
            str += "<td>" + item.Address + "</td>";
            str += "<td>" + item.OrderCount + "</td>";
            str += '<td><div class="btn-group"><button class="btn btn-default btn-xs btn_ri" onclick="GetCustomerDetail(' + item.Id + ');" type="button"><i class="fa fa-share"></i>查看</button>';
            str += '<div class="btn-group"><button class="btn btn-default dropdown-toggle btn-xs" data-toggle="dropdown" type="button" aria-expanded="false">';
            str += '<i class="fa fa-ellipsis-horizontal"></i>更多<i class="fa fa-angle-down"></i></button>';
            str += '<ul class="dropdown-menu pull-right dropdown_wid"><li><a href="javascript:;" onclick="AddOrder(' + item.Id + ');"><i class="fa fa-edit"></i> 追单 </a></li>';
            str += '<li><a href="javascript:;" onclick="Update(' + item.Id + ');"><i class="fa fa-pencil"></i> 修改 </a></li><li><a href="javascript:;" onclick="Delete(' + item.Id + ');"><i class="glyphicon glyphicon-trash"></i> 删除 </a></li></ul></div></div></td></tr>';

            
            //str += '<td><div class="btn-group"><button class="btn btn-default btn-xs btn_ri" type="button" onclick="GetCustomerDetail(' + item.Id + ');"><i class="fa fa-pencil"></i>查看</button>';
            //str += '<button class="btn btn-default btn-xs btn_ri" type="button" onclick="AddOrder(' + item.Id + ');"><i class="fa fa-share"></i>追单</button></div></td></tr>';

        })
        return str;
    }

    function GetCustomerDetail(id) {
        location.href = "/Home/GetCustomerDetail?Id=" + id;
    }
    function AddOrder(id) {
        location.href = "/Home/AddOrder?CustomerId=" + id;
    }

    function Delete(id) {
        layer.confirm('请再次确认是否删除此客户？', {
            btn: ['确定', '取消'] //按钮
        }, function () {
            $.ajax({
                url: "/Home/DeleteCustomer",
                type: "post",
                data: { CustomerId: id },
                success: function (result) {
                    if (result.success) {
                        layer.msg('删除成功', { icon: 1 });
                        setTimeout("location.reload();", 1000)
                    }
                }

            });
        }, function () {

        });
    }

    function Update(id) {
        location.href = "/Home/UpdateCustomer?CustomerId=" + id;
    }


</script>